//
// Created by wujehy on 2020/6/24.
//

#ifndef SMARTPOINTERTEST_SHAREDCLASS_H
#define SMARTPOINTERTEST_SHAREDCLASS_H

#include <memory>

/**
 * @brief 智能指针的高级用法
 */
class SharedClass : public std::enable_shared_from_this<SharedClass>
{
private:
    int id;
    std::string name;
public:
    SharedClass(int id, const std::string &name);
    virtual ~SharedClass();

    int getId() const;

    const std::string &getName() const;

    void setName(const std::string &name);

    std::shared_ptr<SharedClass> getMySelf() {
        //　返回自身
        return shared_from_this();
    }
};

#endif //SMARTPOINTERTEST_SHAREDCLASS_H
